package airthmetic.exercise.arr;

public class _66_加一 {

    public static int[] plusOne(int[] digits) {
        // 定义进位
        int carry = 1;

        for (int i = digits.length -1; i >=0 ; i--) {
            int temp = (digits[i] + carry);
            digits[i] = temp % 10;
            carry = temp / 10;

            if (carry ==0) {
                break;
            }
        }

        if (carry > 0){
            int[] newInt = new int[digits.length + 1];
            newInt[0] = 1;
            return newInt;
        }
        return digits;

    }


    public static void main(String[] args) {
        int [] digits = new int[]{9};
        int[] ints = plusOne(digits);
        for (int anInt : ints) {
            System.out.println(anInt);
        }

    }
}
